<template>
  <div>
    <el-form :model="position" :rules="rules" ref="positionForm" label-width="120px" style="width: 500px">
      <el-form-item label="职位名" prop="jobName">
        <el-input v-model="position.jobName"></el-input>
      </el-form-item>
      <el-form-item label="职位描述" prop="jobDesc">
        <el-input v-model="position.jobDesc"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-radio-group v-model="position.status">
          <el-radio label="1" >开启</el-radio>
          <el-radio label="2" >关闭</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="面试官" prop="interviewerId">
        <el-select v-model="position.interviewerId" placeholder="请选择面试官">
          <el-option label="面试官1" value="1"></el-option>
          <el-option label="面试官2" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="提示词前缀" prop="prompt">
        <el-input type="textarea" v-model="position.prompt" rows="10"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">立即提交</el-button>
        <el-button @click="resetForm">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import axios from "axios";
export default {
  data() {
    return {
      position: {

      },
      rules: {
        jobName: [
          { required: true, message: '职位名不能为空', trigger: 'blur' }
        ],
        jobDesc: [
          { required: true, message: '请输入职位描述', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请选择状态', trigger: 'change' }
        ],
        interviewerId: [
          { required: true, message: '请选择面试官', trigger: 'change' }
        ],
        prompt: [
          { required: true, message: '请输入提示词前缀', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm() {
      this.$refs.positionForm.validate((valid) => {
        if (valid) {
          axios.post('http://localhost:8781/job/addJob', this.position).then(res=>{
            console.log(res)
            if(res.data.code==200){
              this.$message.success(res.data.msg);
              this.$router.push('/jobList');
            }else{
              this.$message.error(res.data.msg);
            }
          })
          // 这里可以添加提交表单数据的逻辑，例如发送axios请求
          console.log('表单提交成功', this.position);
        } else {
          console.log('表单验证失败');
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.positionForm.resetFields();
    }
  }
};
</script>

<style scoped>
</style>